package com.tsinghuabigdata.edu.ddmath.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tsinghuabigdata.edu.ddmath.R;
import com.tsinghuabigdata.edu.ddmath.bean.SubmitQuestion;
import com.tsinghuabigdata.edu.ddmath.util.DateUtils;

import java.util.List;



/**
 * Created by Administrator on 2017/2/17.
 */

public class MonthSubmitedAdatper extends CommonAdapter<SubmitQuestion> {

    String[] weeks = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};

    public MonthSubmitedAdatper(Context context, List<SubmitQuestion> mDatas) {
        super(context, mDatas);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_month_submited;
    }

    @Override
    protected void convert(ViewHolder helper, int position, SubmitQuestion item) {
        LinearLayout llToCorrect = helper.getView(R.id.ll_to_correct);
        LinearLayout llRightCount = helper.getView(R.id.ll_right_count);
        LinearLayout llWrongCount = helper.getView(R.id.ll_wrong_count);
//        TextView tvRightCount = helper.getView(R.id.tv_right_count);
//        TextView tvWrongCount = helper.getView(R.id.tv_wrong_count);
//        RelativeLayout rlCorrectCount = helper.getView(R.id.rl_correct_count);
        ImageView ivOverdue = helper.getView(R.id.iv_overdue);
        if (item.getExerStatus() == 3) {
            llRightCount.setVisibility(View.VISIBLE);
            llWrongCount.setVisibility(View.VISIBLE);
            llToCorrect.setVisibility(View.INVISIBLE);
            helper.setText(R.id.tv_right_count, item.getRightQuestionCount() + "题");
            helper.setText(R.id.tv_wrong_count, item.getWrongQuestionCount() + "题");
        } else {
            llRightCount.setVisibility(View.INVISIBLE);
            llWrongCount.setVisibility(View.INVISIBLE);
            llToCorrect.setVisibility(View.VISIBLE);
        }
        String day = item.getStartTime().substring(8, 10);
        if (day.startsWith("0")){
            day = item.getStartTime().substring(9, 10);
        }
        if (item.getStartTime().equals(DateUtils.getToday())) {
            helper.setText(R.id.tv_day, "今日");
        } else {
            helper.setText(R.id.tv_day, day+"日");
        }
        String week = weeks[item.getWeek()];
        helper.setText(R.id.tv_week, week);

        if (item.isOverdue()) {
            ivOverdue.setVisibility(View.VISIBLE);
        } else {
            ivOverdue.setVisibility(View.INVISIBLE);
        }

        //        String week = weeks[item.getWeekDay()];
        //        helper.setText(R.id.tv_week, week);
    }

    public void setData(List<SubmitQuestion> questions) {
        mDatas.clear();
        mDatas.addAll(questions);
    }
}
